package cn.virens.web.components.shiro;

import javax.servlet.Filter;

import org.apache.shiro.spring.web.ShiroFilterFactoryBean;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import cn.virens.web.components.spring.ApplicationContextUtil;

public class SimpleShiroFilterFactoryBean extends ShiroFilterFactoryBean implements ApplicationContextAware, InitializingBean {

	@Override
	public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
		ApplicationContextUtil.inject(getFilters(), applicationContext);
	}

	@Override
	public void afterPropertiesSet() throws Exception {
		ApplicationContextUtil.init(getFilters());
	}

	public void addFilter(String definition, Filter filter) {
		this.getFilters().put(definition, filter);
	}

	public void addFilterChain(String antPath, String definition) {
		this.getFilterChainDefinitionMap().put(antPath, definition);
	}

	public void addFilterChain(String antPath, String definition, Filter filter) {
		this.getFilterChainDefinitionMap().put(antPath, definition);
		this.getFilters().put(definition, filter);
	}

}
